home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5345 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.mcs.net!mdp
  2. From: mdp@mika-sys.com (Michael D. Perry)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What the heck is ...?
  5. Date: Mon, 12 Feb 96 06:14:16 GMT
  6. Organization: MIKA Systems
  7. Message-ID: <4fmlro$nfg_001@pr.mcs.net>
  8. References: <sconi-1102961642580001@ip-24.newportnet.net>
  9. NNTP-Posting-Host: mdp.pr.mcs.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <sconi-1102961642580001@ip-24.newportnet.net>,
  13.    sconi@superstore.com (Chris Tiee "Chochoni Boboni") wrote:
  14. >Here's something all the books love to avoid: The use of ... in 
  15. function
  16. >declarations. For example, one book says that the prototype of 
  17. printf() is
  18. >
  19. >int printf(const char *fmt_string, ...);
  20. >
  21.  
  22. << SNIP >>
  23.  
  24. What the ellipses mean is that it is a repeatable item.  In the 
  25. case that you cite it takes the place of saying that all of the 
  26. following statements are valid:
  27.  
  28. printf("This is a test");
  29.     /* Note the lack of a comma */
  30.  
  31. int a = 2;
  32. printf("This is test number %d", a);
  33.  
  34. Prints:    This is test number 2
  35.     /* Where the '%d' is a format specifier, and 'a' is a     
  36.     numeric variable */
  37.  
  38. printf("This is test number %d", 2);
  39.     /* Prints exactly the same as the line above except does    
  40.     not use a variable */
  41.  
  42. int a = 2;
  43. int b = 3;
  44. printf("Test %d, is followed by test %d", a b);
  45. Prints: Test 2 is followed by test 3
  46.  
  47. So logic follow that:
  48.  
  49. printf("%d, %d, %d, %d, %d, %d, %d", 1 2 3 4 5 6 7);
  50.  
  51. is the same as:
  52.  
  53. printf("%d, ..., %d", 1 ... 7);
  54.  
  55. and is simply much easier to type and accounts for any number of 
  56. variables.
  57.  
  58. -------------------------------------------------------------------
  59. Michael D. Perry      |   FIRST RULE OF INTELLIGENT TINKERING:
  60. MIKA Systems          |       Save all the parts.
  61. Glen Ellyn, Illinois    |   SATTINGER'S LAW:
  62. mdp@mika-sys.com |       It works better if you plug it in.
  63. -------------------------------------------------------------------
  64.